﻿package org.flixel.system
{
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import org.flixel.*;
    import org.flixel.system.debug.*;

    public class FlxDebugger extends Sprite
    {
        public var perf:Perf;
        public var log:Log;
        public var watch:Watch;
        public var vcr:VCR;
        public var vis:Vis;
        public var hasMouse:Boolean;
        protected var _layout:uint;
        protected var _screen:Point;
        protected var _gutter:uint;

        public function FlxDebugger(param1:Number, param2:Number)
        {
            visible = false;
            this.hasMouse = false;
            this._screen = new Point(param1, param2);
            addChild(new Bitmap(new BitmapData(param1, 15, true, 2130706432)));
            var _loc_3:* = new TextField();
            _loc_3.x = 2;
            _loc_3.width = 160;
            _loc_3.height = 16;
            _loc_3.selectable = false;
            _loc_3.multiline = false;
            _loc_3.defaultTextFormat = new TextFormat("Courier", 12, 16777215);
            var _loc_4:* = FlxG.getLibraryName();
            if (FlxG.debug)
            {
                _loc_4 = _loc_4 + " [debug]";
            }
            else
            {
                _loc_4 = _loc_4 + " [release]";
            }
            _loc_3.text = _loc_4;
            addChild(_loc_3);
            this._gutter = 8;
            var _loc_5:* = new Rectangle(this._gutter, 15 + this._gutter / 2, this._screen.x - this._gutter * 2, this._screen.y - this._gutter * 1.5 - 15);
            this.log = new Log("log", 0, 0, true, _loc_5);
            addChild(this.log);
            this.watch = new Watch("watch", 0, 0, true, _loc_5);
            addChild(this.watch);
            this.perf = new Perf("stats", 0, 0, false, _loc_5);
            addChild(this.perf);
            this.vcr = new VCR();
            this.vcr.x = (param1 - this.vcr.width / 2) / 2;
            this.vcr.y = 2;
            addChild(this.vcr);
            this.vis = new Vis();
            this.vis.x = param1 - this.vis.width - 4;
            this.vis.y = 2;
            addChild(this.vis);
            this.setLayout(FlxG.DEBUGGER_STANDARD);
            addEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver);
            addEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut);
            return;
        }// end function

        public function destroy() : void
        {
            this._screen = null;
            removeChild(this.log);
            this.log.destroy();
            this.log = null;
            removeChild(this.watch);
            this.watch.destroy();
            this.watch = null;
            removeChild(this.perf);
            this.perf.destroy();
            this.perf = null;
            removeChild(this.vcr);
            this.vcr.destroy();
            this.vcr = null;
            removeChild(this.vis);
            this.vis.destroy();
            this.vis = null;
            removeEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver);
            removeEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut);
            return;
        }// end function

        protected function onMouseOver(event:MouseEvent = null) : void
        {
            this.hasMouse = true;
            return;
        }// end function

        protected function onMouseOut(event:MouseEvent = null) : void
        {
            this.hasMouse = false;
            return;
        }// end function

        public function setLayout(param1:uint) : void
        {
            this._layout = param1;
            this.resetLayout();
            return;
        }// end function

        public function resetLayout() : void
        {
            switch(this._layout)
            {
                case FlxG.DEBUGGER_MICRO:
                {
                    this.log.resize(this._screen.x / 4, 68);
                    this.log.reposition(0, this._screen.y);
                    this.watch.resize(this._screen.x / 4, 68);
                    this.watch.reposition(this._screen.x, this._screen.y);
                    this.perf.reposition(this._screen.x, 0);
                    break;
                }
                case FlxG.DEBUGGER_BIG:
                {
                    this.log.resize((this._screen.x - this._gutter * 3) / 2, this._screen.y / 2);
                    this.log.reposition(0, this._screen.y);
                    this.watch.resize((this._screen.x - this._gutter * 3) / 2, this._screen.y / 2);
                    this.watch.reposition(this._screen.x, this._screen.y);
                    this.perf.reposition(this._screen.x, 0);
                    break;
                }
                case FlxG.DEBUGGER_TOP:
                {
                    this.log.resize((this._screen.x - this._gutter * 3) / 2, this._screen.y / 4);
                    this.log.reposition(0, 0);
                    this.watch.resize((this._screen.x - this._gutter * 3) / 2, this._screen.y / 4);
                    this.watch.reposition(this._screen.x, 0);
                    this.perf.reposition(this._screen.x, this._screen.y);
                    break;
                }
                case FlxG.DEBUGGER_LEFT:
                {
                    this.log.resize(this._screen.x / 3, (this._screen.y - 15 - this._gutter * 2.5) / 2);
                    this.log.reposition(0, 0);
                    this.watch.resize(this._screen.x / 3, (this._screen.y - 15 - this._gutter * 2.5) / 2);
                    this.watch.reposition(0, this._screen.y);
                    this.perf.reposition(this._screen.x, 0);
                    break;
                }
                case FlxG.DEBUGGER_RIGHT:
                {
                    this.log.resize(this._screen.x / 3, (this._screen.y - 15 - this._gutter * 2.5) / 2);
                    this.log.reposition(this._screen.x, 0);
                    this.watch.resize(this._screen.x / 3, (this._screen.y - 15 - this._gutter * 2.5) / 2);
                    this.watch.reposition(this._screen.x, this._screen.y);
                    this.perf.reposition(0, 0);
                    break;
                }
                case FlxG.DEBUGGER_STANDARD:
                {
                }
                default:
                {
                    this.log.resize((this._screen.x - this._gutter * 3) / 2, this._screen.y / 4);
                    this.log.reposition(0, this._screen.y);
                    this.watch.resize((this._screen.x - this._gutter * 3) / 2, this._screen.y / 4);
                    this.watch.reposition(this._screen.x, this._screen.y);
                    this.perf.reposition(this._screen.x, 0);
                    break;
                    break;
                }
            }
            return;
        }// end function

    }
}
